//
//  HealthDetailsViewController.m
//  SHHCPhone
//
//  Created by sheng long on 14-7-1.
//  Copyright (c) 2014年 sheng long. All rights reserved.
//

#import "HealthDetailsViewController.h"

@interface HealthDetailsViewController ()
{
    UILabel *titleLabel;
    UILabel *timeLabel;
}
@end

@implementation HealthDetailsViewController

@synthesize listInfo;

- (void)viewDidLoad
{
    [super viewDidLoad];

    navigationBarView.title = @"健康动态详情";
    [navigationBarView setNormalLeftButton];
}

-(void)showView:(HealthViewInfo*)info
{
    titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(12, 16+NAVIGATIONBAR_HEIGHT, CURRENT_CONTENT_WIDTH-12*2, 18)];
    [titleLabel setTextColor:GET_COLOR(@"fc8eb6")];
    [titleLabel setBackgroundColor:[UIColor clearColor]];
    [titleLabel setFont:[UIFont boldSystemFontOfSize:16]];
    [self.view addSubview:titleLabel];
    [titleLabel setText:info.title];
    
    timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(titleLabel.frame.origin.x+2, titleLabel.frame.size.height+titleLabel.frame.origin.y+8, titleLabel.frame.size.width-2*2, 11)];
    [timeLabel setTextColor:GET_COLOR(@"bbbbbb")];
    [timeLabel setBackgroundColor:[UIColor clearColor]];
    [timeLabel setFont:[UIFont systemFontOfSize:10]];
    [self.view addSubview:timeLabel];
    [timeLabel setText:info.pubtime];

    UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, timeLabel.frame.size.height+timeLabel.frame.origin.y+10, CURRENT_CONTENT_WIDTH, CURRENT_CONTENT_HEIGHT-(timeLabel.frame.size.height+timeLabel.frame.origin.y+10))];
    [self.view addSubview:webView];
    [webView loadHTMLString:info.content baseURL:nil];
    [webView.scrollView setBounces:NO];
}

-(void)viewWillAppear:(BOOL)animated
{
    [self againLoading];
//    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithCapacity:1];
//    [dic setValue:IOS_HEALTHDYNAMICDETAIL forKey:IOS_METHOD_NAME];
//    [dic setValue:listInfo.id forKey:@"id"];
//    
//    [self showProgressView:nil belowSubview:navigationBarView];
//    ASIHTTPRequest *request =  [NetUtls httpGet:self withValue:dic tag:IOS_HEALTHDYNAMICDETAIL_TAG need:NO];
////    [self.netArray addObject:request];
//    [request startAsynchronous];
}

//重新加载数据
-(void)againLoading
{
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithCapacity:1];
    [dic setValue:IOS_HEALTHDYNAMICDETAIL forKey:IOS_METHOD_NAME];
    [dic setValue:listInfo.id forKey:@"id"];
    
    [self showProgressView:nil belowSubview:navigationBarView];
    ASIHTTPRequest *request =  [NetUtls httpGet:self withValue:dic tag:IOS_HEALTHDYNAMICDETAIL_TAG need:NO];
    [self.netArray addObject:request];
    [request startAsynchronous];
}

#pragma mark - ASIHTTPRequestDelegate
-(void)requestFinished:(ASIHTTPRequest *)request
{
    CLog(@"%@",[request responseString]);
    NSDictionary *dic = [[request responseString] objectFromJSONString];
    if (dic != nil) {
        [self hideProgressView];
        HealthViewInfo *info = [[HealthViewInfo alloc] init:dic];
        [self showView:info];
    }else{
        [self requestFailed:request];
    }
}

-(void)requestFailed:(ASIHTTPRequest *)request
{
    [self clickAgainLoadingView:0];
}

@end
